/**
 *
 */
package com.security2.demo.authentication;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.security2.demo.domain.ReturnInfo;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName AuthLimitHandler
 * @Description 退出自定义实现类
 * @Author Liujt
 * @Date 2020/1/15 17:02
 **/
@Component
public class MyLogoutSuccessHandler implements LogoutSuccessHandler {

    private ObjectMapper objectMapper = new ObjectMapper();

    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
            throws IOException {
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().write(objectMapper.writeValueAsString(new ReturnInfo<>("退出成功")));

    }

}
